﻿using netDxf;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Tables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestDxfDocument

{

    class ISYC_309_09
    {
        //图F.100  ISYC 309-09-法兰接触式连接的可转位刀片内孔车削系统
        public static void ISYC_309_09_g(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //基本参数-------------------------------------------------------------------------------------------------
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            //赋值参数--------------------------------------------------------------------------------------------------
            double sl_ = Convert.ToDouble(data["oal"]);
            double scale = Convert.ToDouble(data["scale"]);
          //      double sl_ = 45;
          //      double scale = 1;
            if (sl_ <= 67)
            {
                scale = 4;
            }
            else if (67 < sl_ && sl_ <= 75)
            {
                scale = 2.5;
            }
            else if (75 < sl_ && sl_ <= 100)
            {
                scale = 2;
            }
            else
            {
                scale = 1;
            }/*
            double dconms = 10 * scale;
            double oal = 25 * scale;
            double lpr = 19.54 * scale;
            double lf = 18.92 * scale;
            double lu = 15.94 * scale;
            double lb = 15.91 * scale;
            double wfa = 2.272 * scale;
            double wf = 3.754 * scale;
            double bd = 4.45 * scale;
            double kapr = 75;
            double kapr_ = kapr * pi / 180;*/
            double dconms = Convert.ToDouble(data["dconms"]) * scale;
            double oal = Convert.ToDouble(data["oal"]) * scale;
            double lpr = Convert.ToDouble(data["lpr"]) * scale;
            double lf = Convert.ToDouble(data["lf"]) * scale;
            double lu = Convert.ToDouble(data["lu"]) * scale;
            double lb = Convert.ToDouble(data["lb"]) * scale;
            double wfa = Convert.ToDouble(data["wfa"]) * scale;
            double wf = Convert.ToDouble(data["wf"]) * scale;
            double bd = Convert.ToDouble(data["bd"]) * scale;
            double kapr = Convert.ToDouble(data["kapr"]);
            double kapr_ = kapr * pi / 180;
            
            //点---------------------------------------------------------------------------------------------
            //第一部分
            //非切削部分
            Vector2 p0 = new Vector2(0, 0);
            Vector2[] vis(Vector2 p)
            {
                Vector2 p1_0; Vector2 p2_0; Vector2 p3_0; Vector2 p4_0; Vector2 p5;
                p1_0 = fun.Polar(p, pi / 2, dconms / 2.0);
                p2_0 = fun.Polar(p, pi / -2, dconms / 2.0);
                p3_0 = fun.Polar(p2_0, pi, 2.32 / 19.54 * lpr);
                p4_0 = fun.Polar(p1_0, pi, fun.CalDistance(p2_0, p3_0));
                p5 = fun.Polar(p3_0, pi / 2, dconms / 12.5);
                Vector2 p6 = fun.Polar(p5, pi - 5 * pi / 180, ((oal - lpr) / Math.Cos(5 * pi / 180)) - ((0.4 / 4.96) * (oal - lpr)));
                Vector2 p7_0 = fun.Polar(fun.Polar(p5, pi / 2, fun.CalDistance(p4_0, p5) / 2.0), pi, oal - lpr);
                Vector2 p7_1 = fun.Polar(p7_0, pi / 2, dconms);
                Vector2 p7_2 = fun.Polar(p7_0, pi / -2, dconms);
                Vector2 p7_3 = fun.Polar(p6, fun.CalAngle(p5, p6) - pi / 4, dconms);
                Vector2 p7_4 = fun.Inters(p6, p7_3, p7_1, p7_2);
                Vector2 p8_0 = fun.Polar(p4_0, pi / -2, fun.CalDistance(p3_0, p5));
                Vector2 p9_0 = fun.Polar(p8_0, pi + 5 * pi / 180, fun.CalDistance(p5, p6));
                Vector2 p1_00 = fun.Polar(p9_0, (-fun.CalAngle(p6, p7_4)), fun.CalDistance(p6, p7_4));
                var polyline1 = Pus.AddPointsToLwPolyLine(p8_0, p4_0, p1_0, p2_0, p3_0, p8_0, p9_0, p1_00, p7_4, p6, p9_0, p6, p5);
                dxf.AddEntity(polyline1);
                fun.PolyFill(dxf, polyline1, 0.5, contour);
                Vector2[] pj = { p1_0, p2_0, p3_0, p4_0, p7_4, p8_0, p9_0 };
                return pj;
            }

            //切削部分
            Vector2[] pj_1 = vis(p0);
            Vector2 p0_1 = fun.Polar(p0, pi, oal - lb);
            Vector2 p0_2 = fun.Polar(p0, 0, lpr);
            Line line1 = new Line(p0_1, p0_2);
            line1.Lineweight = Lineweight.W25;//Lineweight指线宽
            line1.Layer = additionalline;//Layer指图层
            line1.LinetypeScale = 5 * scale;//指线性比例
            line1.Linetype = Linetype.DashDot;//Linetype指是点划线还是虚线什么的
            dxf.AddEntity(line1); //提取
            Vector2 p1 = pj_1[0];
            Vector2 p2 = pj_1[1];
            Vector2 p3 = pj_1[2];
            Vector2 p4 = pj_1[3];
            Vector2 p7 = pj_1[4];
            Vector2 p8 = pj_1[5];
            Vector2 p9 = pj_1[6];
            Vector2 p11 = new Vector2(p0.X - fun.CalDistance(p2, p3) + lpr, 0);
            Vector2 p12 = fun.Polar(p11, pi, lb / 4.0);
            Vector2 p13 = fun.Polar(p12, pi - pi / 4, bd / 2.0 * (Math.Sqrt(2)));
            Vector2 p14_1 = fun.Polar(p1, -pi / 3, dconms);
            Vector2 p14_2 = fun.Polar(p13, pi, lb);
            Vector2 p14 = fun.Inters(p13, p14_2, p1, p14_1);
            Vector2 p15 = fun.mirrorpoint(p13, p0_1, p0_2);
            Vector2 p16 = fun.mirrorpoint(p14, p0_1, p0_2);
            Vector2 p17 = fun.Polar(p11, pi / -2, bd * (0.4 / 4.56));
            Vector2 p18 = fun.Polar(p17, pi, wfa / 8.0);
            Vector2 p19 = fun.Polar(p18, pi / -2, bd / 2.0 + bd / 30.0);
            Vector2 p20 = fun.Polar(p19, pi, (p19.X - p15.X) * (2 / 3.0));
            Vector2 p21 = fun.Polar(p20, pi / 2, bd / 30.0 - p18.Y);
            Vector2 p22 = fun.Polar(p12, 0, fun.CalDistance(p11, p17));
            Vector2 p23 = fun.Inters(p22, fun.Polar(p22, pi / -2, lb), p19, p20);
            Vector2 p24 = fun.Inters(p12, fun.Polar(p12, pi / -2, lb), p19, p20);
            Vector2 p25 = fun.Polar(p17, pi, wfa);
            Vector2 p26 = fun.Polar(p11, pi, wfa);
            Vector2 arc1_1 = fun.Polar(p12, pi / -2, 0.1);
            Vector2 arc1_2 = fun.Polar(arc1_1, pi - pi / 6, lb);
            Arc arc1 = fun.DrawArc5(p13, new Line(arc1_1, arc1_2), p12);
            //第二部分
            //非切削部分
            Vector2 p0_4 = fun.Polar(p0, pi / -2, dconms * 3);
            Vector2 p0_5 = fun.Polar(p0_4, pi, oal - lb);
            Vector2 p0_6 = fun.Polar(p0_4, 0, lpr);
            Line line2 = new Line(p0_5, p0_6);
            line2.Lineweight = Lineweight.W25;//Lineweight指线宽
            line2.Layer = additionalline;//Layer指图层
            line2.LinetypeScale = 5 * scale;//指线性比例
            line2.Linetype = Linetype.Dashed;//Linetype指是点划线还是虚线什么的
            dxf.AddEntity(line2); //提取
            //切削部分
            Vector2[] pj_2 = vis(p0_4);
            Vector2 p1_10 = pj_2[0];
            Vector2 p2_10 = pj_2[1];
            Vector2 p3_10 = pj_2[2];
            Vector2 p4_10 = pj_2[3];
            Vector2 p7_10 = pj_2[4];
            Vector2 p8_10 = pj_2[5];
            Vector2 p9_10 = pj_2[6];
            Vector2 p27 = fun.Polar(p1_10, fun.CalAngle(p1, p14), fun.CalDistance(p1, p14));
            Vector2 p28 = fun.Polar(p2_10, fun.CalAngle(p2, p16), fun.CalDistance(p2, p16));
            Vector2 p29_1 = fun.Polar(p0_4, pi, fun.CalDistance(p1, p4));
            Vector2 p29 = fun.Polar(p29_1, 0, lpr - lpr / 50.0);
            Vector2 p30 = fun.Polar(p29, pi / 2, bd / 10.0);
            Vector2 p31_1 = fun.Polar(p27, 0, oal);
            Vector2 p31_2 = fun.Polar(p30, pi / 2 + pi / 6, lb);
            Vector2 p31 = fun.Inters(p27, p31_1, p30, p31_2);
            Vector2 p32 = fun.Inters(p31, p27, p24, fun.Polar(p24, pi / -2, oal * 2));
            Vector2 p33 = fun.Inters(p28, fun.Polar(p28, 0, oal), p24, fun.Polar(p24, pi / -2, oal * 2));
            Vector2 p34_1 = fun.Polar(p33, pi / -2, bd / 3.0);
            Vector2 p34_2 = fun.Polar(p34_1, 0, lb);
            Vector2 p34 = fun.Inters(p34_1, p34_2, p23, fun.Polar(p23, pi / -2, oal * 2));
            Vector2 p35 = fun.Polar(p33, pi, p34.X - p33.X);
            Vector2 p36 = fun.Polar(p32, pi, fun.CalDistance(p33, p35));
            Vector2 p37 = fun.Inters(p34, fun.Polar(p34, 0, lb), p29, fun.Polar(p29, pi / -2, lb));
            Vector2 p38 = fun.Polar(p37, pi - pi / 4, (Math.Sqrt(2) * (wfa / 2.0)) / 2.0);
            Vector2 p39 = fun.Polar(p38, pi / 4 - (pi / 2 - kapr_), (Math.Sqrt(2) * (wfa / 2.0)));
            Vector2 p40 = fun.Polar(p39, fun.CalAngle(p39, p38) + pi / 4, wfa);
            Vector2 p41 = fun.Polar(p40, fun.CalAngle(p40, p39) + pi / 2, wfa);
            Vector2 p42 = fun.Polar(p41, fun.CalAngle(p41, p40) + pi / 2, wfa);
            Vector2 p43 = fun.Inters(p42, p39, p29, fun.Polar(p29, pi / -2, lb));
            Vector2 p44 = fun.Inters(p42, p41, p34, fun.Polar(p34, 0, lb));
            Arc arc2 = fun.DrawArc5(p36, new Line(p13, fun.Polar(p13, pi / -2 - 0.1 * pi / 180, oal * 2)), p35);

            var polyline2 = Pus.AddPointsToLwPolyLine(p13, p14, p1, p2, p16, p14, p16, p15, p13, p15, p21, p20, p24, p12, p26, p22, p23, p24, p19, p18,
                p25, p26, p11, p17, p18);
            var polyline3 = Pus.AddPointsToLwPolyLine(p44, p34, p33, p28, p2_10, p1_10, p27, p28, p27, p31, p30, p29, p43);
            var polyline4 = Pus.AddPointsToLwPolyLine(p40, p41, p42, p39, p40);
            dxf.AddEntity(new EntityObject[] { polyline2,polyline3 ,polyline4
            ,arc1 ,arc2
            });
            fun.PolyFill(dxf, polyline2, 0.5, contour);
            fun.PolyFill(dxf, polyline3, 0.5, contour);
            fun.PolyFill(dxf, polyline4, 0.5, contour);
            fun.drawBArc(dxf, arc1, 0.5, contour);
            fun.drawBArc(dxf, arc2, 0.5, contour);
            //标注
            
            Vector2 v1 = fun.Polar(p2_10, fun.CalAngle(p2_10, p28), fun.CalDistance(p2_10, p28) / 3.0);
            Vector2 v2 = fun.Polar(p9_10, fun.CalAngle(p9_10, p8_10), fun.CalDistance(p9_10, p8_10) / 3.0);
            Vector2 v3 = fun.Polar(p40, pi / -6 / 2, dconms * 2);
            Vector2 v4 = fun.Polar(p3, pi / 2, fun.CalDistance(p3, p4) / 2.0);
            Vector2 v5 = fun.Polar(p26, 0, fun.CalDistance(p26, p11) / 2.0);
            Vector2 v6 = fun.Polar(p3_10, pi / 2, fun.CalDistance(p3_10, p4_10) / 2.0);
            Vector2 v7 = fun.Polar(v4, pi + 80 * pi / 180, 0.2 * 1.7 * scale);
            Vector2 v8 = fun.Polar(v7, pi + 80 * pi / 180, (fun.CalDistance(v4, v6) / 2.0) / Math.Cos(20 * pi / 180));
            Vector2 v9 = fun.Polar(v8, pi / -2, 0.8 * scale);
            Vector2 v10 = fun.Polar(v6, pi / 2 + 10 * pi / 180, 0.2 * 1.7 * scale);
            Vector2 v11 = fun.Polar(v5, pi - pi / 4, 0.2 * 1.7 * scale);
            Vector2 v12 = fun.Polar(v11, pi - pi / 4, dconms / 2.0);
            Vector2 v13 = fun.Polar(v5, 0, 0.2 * 1.7 * scale * 2);
            Vector2 v14 = fun.Polar(v13, pi / -4, 0.2 * 1.7 * scale);
            Vector2 v15 = fun.Polar(v14, pi / -4, dconms / 4);
            Vector2 v16 = fun.Polar(v15, pi / -2, 0.8 * scale);
            Vector2 v17 = fun.Polar(p38, pi + pi / 4, 0.2 * 1.7 * scale);
            Vector2 v18 = fun.Polar(v17, pi + pi / 4, dconms / 4);
            Vector2 v19 = fun.Polar(v18, pi / -2, 0.8 * scale);
            Vector2 v20 = fun.Polar(p40, pi / -4, 0.2 * 1.7 * scale);
            Vector2 v21 = fun.Polar(v20, pi / -4, dconms / 4.0);
            Vector2 v22 = fun.Polar(v21, pi / -2, 0.8 * scale);
            fun.dimrot1(dxf, p26, p11, -90, dconms * 1.5, 2, 0.8 * scale, 1.2 * scale, 0.9, "HF,HTA", "", "");
            fun.dimrot1(dxf, p27, p39, 0, dconms / 2.0, 2, 0.8 * scale, 1.2 * scale, 0.9, "LB", "", "");
            fun.dimrot1(dxf, p4_10, p3_10, 90, dconms, 2, 0.8 * scale, 1.2 * scale, 0.9, "DCONMS", "", "");
            fun.dimrot1(dxf, v1, p40, 180, dconms / 1.5 + ((p40.Y - v1.Y) / 2.0), 2, 0.8 * scale, 1.2 * scale, 0.9, "LU", "", "");
            fun.dimrot1(dxf, p3_10, p40, 180, dconms * 1.5 + ((p3_10.Y - p40.Y) / 2.0) + (p40.Y - p29.Y), 2, 0.8 * scale, 1.2 * scale, 0.9, "LF,LTA", "", "");
            fun.dimrot1(dxf, p40, p39, 180, dconms * 1.5 + ((p40.Y - p39.Y) / 2.0) + (p39.Y - p29.Y), 2, 0.8 * scale, 1.2 * scale, 0.9, "LFA", "", "");
            fun.dimrot1(dxf, p3_10, p39, 180, dconms * 2 + ((p3_10.Y - p39.Y) / 2.0), 2, 0.8 * scale, 1.2 * scale, 0.9, "LPR", "", "");
            fun.dimrot1(dxf, p7_10, p40, 180, dconms * 2.5 + ((p7_10.Y - p40.Y) / 2.0), 2, 0.8 * scale, 1.2 * scale, 0.9, "OAL", "", "");
            fun.dimrot1(dxf, p40, p39, -90, dconms + ((p39.X - p40.X) / 2.0), 2, 0.8 * scale, 1.2 * scale, 0.9, "WFA", "", "");
            fun.dimrot1(dxf, p40, p29, -90, dconms * 1.5 + ((p39.X - p40.X) / 2.0), 2, 0.8 * scale, 1.2 * scale, 0.9, "WF,WTA", "", "");
            fun.dimrot1(dxf, p27, p28, -90, lb / 4.0, 2, 0.8 * scale, 1.2 * scale, 0.9, "BD", "", "");
            fun.jdbz2(dxf, new Line(p40, fun.Polar(p40, 0, 0.1)), new Line(p40, p39), dconms * 2, 0.8 * scale, 1.2 * scale, 0.9, "KAPR", "", "");
            fun.Axis(dxf, v4, 180, 90, "Z", "Y", "", 0.2 * scale, 0.8 * scale, 0);
            fun.Axis(dxf, v5, 180, 90, "Y", "Z", "", 0.2 * scale, 0.8 * scale, 0);
            fun.Axis(dxf, v6, 180, -90, "Z", "X", "", 0.2 * scale, 0.8 * scale, 0);
            fun.Axis(dxf, p38, 180, 90, "Y", "X", "", 0.2 * scale, 0.8 * scale, 0);
            fun.Singlelinearrow(dxf, "CCMS", v2, 145, fun.Polar(v2, 145 * pi / 180, dconms / 2.0), fun.Polar(v2, 145 * pi / 180, dconms), 0.8 * scale, 1.2 * scale);
            fun.Singlelinearrow(dxf, "FDP", v3, 0, fun.Polar(v3, pi, dconms / 4.0), fun.Polar(v3, pi, dconms / 2.0), 0.8 * scale, 1.2 * scale);
            Line linev1 = new Line(v7, v8);
            Line linev2 = new Line(v9, v10);
            Line linev3 = new Line(v11, v12);
            Line linev4 = new Line(v14, v15);
            Line linev5 = new Line(v17, v18);
            Line linev6 = new Line(v20, v21);
            Text txt1 = new Text("PCS,MCS", v9, 0.8 * scale, 0);
            Text txt2 = new Text("CSW", v12, 0.8 * scale, 0);
            Text txt3 = new Text("CRP", v16, 0.8 * scale, 0);
            Text txt4 = new Text("CSW", v19, 0.8 * scale, 0);
            Text txt5 = new Text("CRP", v22, 0.8 * scale, 0);
            Text txt6 = new Text("ISYC=309_09", fun.Polar(p1, pi / 2, dconms / 2.0), 0.8 * scale, 0);
            Circle circle1 = new Circle(v13, 0.2 * 1.7 * scale);
            Circle circle2 = new Circle(p40, 0.2 * 1.7 * scale);
            dxf.AddEntity(new EntityObject[] { linev1,linev2,linev3 ,linev4 ,linev5,linev6
            ,txt1 ,txt2,txt3 ,txt4,txt5,txt6
            ,circle1 ,circle2
            });
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
       
            //图F.100  ISYC 309-09-法兰接触式连接的可转位刀片内孔车削系统
            public static void ISYC_309_09_j(Dictionary<string, Object> data)
            {
                DxfDocument dxf = new DxfDocument();
                //图层
                Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
                Layer dimensioning = new Layer("dimensioning");    //尺寸层
                Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
                Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
                Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
                Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
                Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
                Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
                Layer nocutting = new Layer("nocutting");    //非切削层
                Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
                Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
                Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
                Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
                Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
                Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
                Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
                Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

                //基本参数-------------------------------------------------------------------------------------------------
                double pi = Math.PI;
                string path = Convert.ToString(data["path"]);

                //赋值参数--------------------------------------------------------------------------------------------------
                double sl_ = Convert.ToDouble(data["oal"]);
                double scale = Convert.ToDouble(data["scale"]);
                //   double sl_ = 45;
                //   double scale = 1;
                if (sl_ <= 67)
                {
                    scale = 4;
                }
                else if (67 < sl_ && sl_ <= 75)
                {
                    scale = 2.5;
                }
                else if (75 < sl_ && sl_ <= 100)
                {
                    scale = 2;
                }
                else
                {
                    scale = 1;
                }/*
            double dconms = 10 * scale;
            double oal = 25 * scale;
            double lpr = 19.54 * scale;
            double lf = 18.92 * scale;
            double lu = 15.94 * scale;
            double lb = 15.91 * scale;
            double wfa = 2.272 * scale;
            double wf = 3.754 * scale;
            double bd = 4.45 * scale;
            double kapr = 75;
            double kapr_ = kapr * pi / 180;*/
                double dconms = Convert.ToDouble(data["dconms"]) * scale;
                double oal = Convert.ToDouble(data["oal"]) * scale;
                double lpr = Convert.ToDouble(data["lpr"]) * scale;
                double lf = Convert.ToDouble(data["lf"]) * scale;
                double lu = Convert.ToDouble(data["lu"]) * scale;
                double lb = Convert.ToDouble(data["lb"]) * scale;
                double wfa = Convert.ToDouble(data["wfa"]) * scale;
                double wf = Convert.ToDouble(data["wf"]) * scale;
                double bd = Convert.ToDouble(data["bd"]) * scale;
                double kapr = Convert.ToDouble(data["kapr"]);
                double kapr_ = kapr * pi / 180;
            
                //点---------------------------------------------------------------------------------------------
                //第一部分
                //非切削部分
                Vector2 p0 = new Vector2(0, 0);
                Vector2[] vis(Vector2 p)
                {
                    Vector2 p1_0; Vector2 p2_0; Vector2 p3_0; Vector2 p4_0; Vector2 p5;
                    p1_0 = fun.Polar(p, pi / 2, dconms / 2.0);
                    p2_0 = fun.Polar(p, pi / -2, dconms / 2.0);
                    p3_0 = fun.Polar(p2_0, pi, 2.32 / 19.54 * lpr);
                    p4_0 = fun.Polar(p1_0, pi, fun.CalDistance(p2_0, p3_0));
                    p5 = fun.Polar(p3_0, pi / 2, dconms / 12.5);
                    Vector2 p6 = fun.Polar(p5, pi - 5 * pi / 180, ((oal - lpr) / Math.Cos(5 * pi / 180)) - ((0.4 / 4.96) * (oal - lpr)));
                    Vector2 p7_0 = fun.Polar(fun.Polar(p5, pi / 2, fun.CalDistance(p4_0, p5) / 2.0), pi, oal - lpr);
                    Vector2 p7_1 = fun.Polar(p7_0, pi / 2, dconms);
                    Vector2 p7_2 = fun.Polar(p7_0, pi / -2, dconms);
                    Vector2 p7_3 = fun.Polar(p6, fun.CalAngle(p5, p6) - pi / 4, dconms);
                    Vector2 p7_4 = fun.Inters(p6, p7_3, p7_1, p7_2);
                    Vector2 p8_0 = fun.Polar(p4_0, pi / -2, fun.CalDistance(p3_0, p5));
                    Vector2 p9_0 = fun.Polar(p8_0, pi + 5 * pi / 180, fun.CalDistance(p5, p6));
                    Vector2 p1_00 = fun.Polar(p9_0, (-fun.CalAngle(p6, p7_4)), fun.CalDistance(p6, p7_4));
                    var polyline1 = Pus.AddPointsToLwPolyLine(p8_0, p4_0, p1_0, p2_0, p3_0, p8_0, p9_0, p1_00, p7_4, p6, p9_0, p6, p5);
                  if(p.Y ==0)
                {
                    
                }
                else
                {
                    dxf.AddEntity(polyline1);
                    fun.PolyFill(dxf, polyline1, 0.5, contour);
                }
                    
                    Vector2[] pj = { p1_0, p2_0, p3_0, p4_0, p7_4, p8_0, p9_0 };
                    return pj;
                }

                //切削部分
                Vector2[] pj_1 = vis(p0);
                Vector2 p0_1 = fun.Polar(p0, pi, oal - lb);
                Vector2 p0_2 = fun.Polar(p0, 0, lpr);
                Vector2 p1 = pj_1[0];
                Vector2 p2 = pj_1[1];
                Vector2 p3 = pj_1[2];
                Vector2 p4 = pj_1[3];
                Vector2 p7 = pj_1[4];
                Vector2 p8 = pj_1[5];
                Vector2 p9 = pj_1[6];
                Vector2 p11 = new Vector2(p0.X - fun.CalDistance(p2, p3) + lpr, 0);
                Vector2 p12 = fun.Polar(p11, pi, lb / 4.0);
                Vector2 p13 = fun.Polar(p12, pi - pi / 4, bd / 2.0 * (Math.Sqrt(2)));
                Vector2 p14_1 = fun.Polar(p1, -pi / 3, dconms);
                Vector2 p14_2 = fun.Polar(p13, pi, lb);
                Vector2 p14 = fun.Inters(p13, p14_2, p1, p14_1);
                Vector2 p15 = fun.mirrorpoint(p13, p0_1, p0_2);
                Vector2 p16 = fun.mirrorpoint(p14, p0_1, p0_2);
                Vector2 p17 = fun.Polar(p11, pi / -2, bd * (0.4 / 4.56));
                Vector2 p18 = fun.Polar(p17, pi, wfa / 8.0);
                Vector2 p19 = fun.Polar(p18, pi / -2, bd / 2.0 + bd / 30.0);
                Vector2 p20 = fun.Polar(p19, pi, (p19.X - p15.X) * (2 / 3.0));
                Vector2 p21 = fun.Polar(p20, pi / 2, bd / 30.0 - p18.Y);
                Vector2 p22 = fun.Polar(p12, 0, fun.CalDistance(p11, p17));
                Vector2 p23 = fun.Inters(p22, fun.Polar(p22, pi / -2, lb), p19, p20);
                Vector2 p24 = fun.Inters(p12, fun.Polar(p12, pi / -2, lb), p19, p20);
                Vector2 p25 = fun.Polar(p17, pi, wfa);
                Vector2 p26 = fun.Polar(p11, pi, wfa);
                Vector2 arc1_1 = fun.Polar(p12, pi / -2, 0.1);
                Vector2 arc1_2 = fun.Polar(arc1_1, pi - pi / 6, lb);
                Arc arc1 = fun.DrawArc5(p13, new Line(arc1_1, arc1_2), p12);
                //第二部分
                //非切削部分
                Vector2 p0_4 = fun.Polar(p0, pi / -2, dconms * 3);
                Vector2 p0_5 = fun.Polar(p0_4, pi, oal - lb);
                Vector2 p0_6 = fun.Polar(p0_4, 0, lpr);
                Line line2 = new Line(p0_5, p0_6);
                line2.Lineweight = Lineweight.W25;//Lineweight指线宽
                line2.Layer = additionalline;//Layer指图层
                line2.LinetypeScale = 5 * scale;//指线性比例
                line2.Linetype = Linetype.Dashed;//Linetype指是点划线还是虚线什么的
                dxf.AddEntity(line2); //提取
                                      //切削部分
                Vector2[] pj_2 = vis(p0_4);
                Vector2 p1_10 = pj_2[0];
                Vector2 p2_10 = pj_2[1];
                Vector2 p3_10 = pj_2[2];
                Vector2 p4_10 = pj_2[3];
                Vector2 p7_10 = pj_2[4];
                Vector2 p8_10 = pj_2[5];
                Vector2 p9_10 = pj_2[6];
                Vector2 p27 = fun.Polar(p1_10, fun.CalAngle(p1, p14), fun.CalDistance(p1, p14));
                Vector2 p28 = fun.Polar(p2_10, fun.CalAngle(p2, p16), fun.CalDistance(p2, p16));
                Vector2 p29_1 = fun.Polar(p0_4, pi, fun.CalDistance(p1, p4));
                Vector2 p29 = fun.Polar(p29_1, 0, lpr - lpr / 50.0);
                Vector2 p30 = fun.Polar(p29, pi / 2, bd / 10.0);
                Vector2 p31_1 = fun.Polar(p27, 0, oal);
                Vector2 p31_2 = fun.Polar(p30, pi / 2 + pi / 6, lb);
                Vector2 p31 = fun.Inters(p27, p31_1, p30, p31_2);
                Vector2 p32 = fun.Inters(p31, p27, p24, fun.Polar(p24, pi / -2, oal * 2));
                Vector2 p33 = fun.Inters(p28, fun.Polar(p28, 0, oal), p24, fun.Polar(p24, pi / -2, oal * 2));
                Vector2 p34_1 = fun.Polar(p33, pi / -2, bd / 3.0);
                Vector2 p34_2 = fun.Polar(p34_1, 0, lb);
                Vector2 p34 = fun.Inters(p34_1, p34_2, p23, fun.Polar(p23, pi / -2, oal * 2));
                Vector2 p35 = fun.Polar(p33, pi, p34.X - p33.X);
                Vector2 p36 = fun.Polar(p32, pi, fun.CalDistance(p33, p35));
                Vector2 p37 = fun.Inters(p34, fun.Polar(p34, 0, lb), p29, fun.Polar(p29, pi / -2, lb));
                Vector2 p38 = fun.Polar(p37, pi - pi / 4, (Math.Sqrt(2) * (wfa / 2.0)) / 2.0);
                Vector2 p39 = fun.Polar(p38, pi / 4 - (pi / 2 - kapr_), (Math.Sqrt(2) * (wfa / 2.0)));
                Vector2 p40 = fun.Polar(p39, fun.CalAngle(p39, p38) + pi / 4, wfa);
                Vector2 p41 = fun.Polar(p40, fun.CalAngle(p40, p39) + pi / 2, wfa);
                Vector2 p42 = fun.Polar(p41, fun.CalAngle(p41, p40) + pi / 2, wfa);
                Vector2 p43 = fun.Inters(p42, p39, p29, fun.Polar(p29, pi / -2, lb));
                Vector2 p44 = fun.Inters(p42, p41, p34, fun.Polar(p34, 0, lb));
                Arc arc2 = fun.DrawArc5(p36, new Line(p13, fun.Polar(p13, pi / -2 - 0.1 * pi / 180, oal * 2)), p35);

                var polyline2 = Pus.AddPointsToLwPolyLine(p13, p14, p1, p2, p16, p14, p16, p15, p13, p15, p21, p20, p24, p12, p26, p22, p23, p24, p19, p18,
                    p25, p26, p11, p17, p18);
                var polyline3 = Pus.AddPointsToLwPolyLine(p44, p34, p33,p35,p36,p35, p28, p2_10, p1_10, p27, p28, p27, p31, p30, p29, p43);
                var polyline4 = Pus.AddPointsToLwPolyLine(p40, p41, p42, p39, p40);
              /*  dxf.AddEntity(new EntityObject[] { polyline2,polyline3 ,polyline4
            ,arc1 ,arc2
            });*/
               // fun.PolyFill(dxf, polyline2, 0.5, contour);
                fun.PolyFill(dxf, polyline3, 0.5, contour);
                fun.PolyFill(dxf, polyline4, 0.5, contour);
                //标注
                /* fun.dimrot1(dxf, p1, p18, 90, dc, 2, 2 * scale, 2.4 * scale, 0.9, "DCB", "", "");
           fun.jdbz2(dxf, new Line(p4, p5), new Line(p7, p8), dc, 2 * scale, 2.4 * scale, 0.9, "SIG", "", "");
           fun.Axis(dxf, fun.Polar(p0, pi + pi / 3, dc * 2), 180, -90, "Z", "X", "Y", 1 * scale, 2 * scale, 0);
           fun.Axis(dxf, p0, 180, -90, "", "", "", 1 * scale, 2 * scale, 0);
           fun.Axis(dxf, p19, 180, -90, "", "", "", 1 * scale, 2 * scale, 0);
           fun.Singlelinearrow(dxf, "CCMS", v1, 110, fun.Polar(v1, 110 * pi / 180, dc / 2.0), fun.Polar(v1, 110 * pi / 180, dc), 1.2 * scale, 1.6 * scale);
           Text txt1 = new Text("PCS", v18, 2.2 *scale , 0);
           Circle circle1 = new Circle(p0, 1.7 * 2 * scale) ;
                 */
                Vector2 v1 = fun.Polar(p2_10, fun.CalAngle(p2_10, p28), fun.CalDistance(p2_10, p28) / 3.0);
                Vector2 v2 = fun.Polar(p9_10, fun.CalAngle(p9_10, p8_10), fun.CalDistance(p9_10, p8_10) / 3.0);
            
                fun.dimrot1(dxf, p36, p39, 0, dconms / 2.0, 2, 0.8 * scale, 1.2 * scale, 0.9, "LH", "", "");
                fun.dimrot1(dxf, p4_10, p3_10, 90, dconms, 2, 0.8 * scale, 1.2 * scale, 0.9, "DCONMS", "", "");
                fun.dimrot1(dxf, p28, p40, 180, dconms / 1.2 + ((p40.Y - p28.Y) / 2.0), 2, 0.8 * scale, 1.2 * scale, 0.9, "LDRED", "", "");
                fun.dimrot1(dxf, p3_10, p40, 180, dconms * 1.5 + ((p3_10.Y - p40.Y) / 2.0) + (p40.Y - p29.Y), 2, 0.8 * scale, 1.2 * scale, 0.9, "LF", "", "");
                fun.dimrot1(dxf, p3_10, p39, 180, dconms * 2 + ((p3_10.Y - p39.Y) / 2.0), 2, 0.8 * scale, 1.2 * scale, 0.9, "LPR", "", "");
                fun.dimrot1(dxf, p7_10, p40, 180, dconms * 2.5 + ((p7_10.Y - p40.Y) / 2.0), 2, 0.8 * scale, 1.2 * scale, 0.9, "OAL", "", "");
                fun.dimrot1(dxf, p40, p39, -90 - (90 - kapr), dconms + ((p39.X - p40.X) / 2.0), 2, 0.8 * scale, 1.2 * scale, 0.9, "L", "", "");
                fun.dimrot1(dxf, p40, p29, -90, dconms * 1.5 + ((p39.X - p40.X) / 2.0), 2, 0.8 * scale, 1.2 * scale, 0.9, "WF", "", "");
                fun.dimrot1(dxf, p27, p28, -90, lb / 4.0, 2, 0.8 * scale, 1.2 * scale, 0.9, "BDRED", "", "");
                fun.jdbz2(dxf, new Line(p40, fun.Polar(p40, 0, 0.1)), new Line(p40, p39), dconms * 2, 0.8 * scale, 1.2 * scale, 0.9, "KAPR", "", "");
                fun.jdbz2(dxf, new Line(p40, p41), new Line(p42, p41), dconms / 2.0, 0.8 * scale, 1.2 * scale, 0.9, "EPSR", "", "");
                fun.Singlelinearrow(dxf, "CCTMS,CCFMS,CZCMS", v2, 145, fun.Polar(v2, 145 * pi / 180, dconms / 2.0), fun.Polar(v2, 145 * pi / 180, dconms), 0.8 * scale, 1.2 * scale);

            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }

            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
                dxf.Save(path);
            }
        }
}